package cn.edu.nju.ws.sview.views.listener;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;
import java.util.Properties;
import java.util.TimerTask;

import cn.edu.nju.ws.sview.database.DBConnectionFactory;
/**
 * 每过一段时间去数据库中回收软件制品编辑权限
 * @author Saisai Gong
 *
 */
public class AuthoriyRecoveryTask  extends TimerTask{
	public final static int RECOVERY_MINUTE;
	static{
		 Properties properties = new Properties();
	   	 try {
				properties.load(AuthoriyRecoveryTask.class.getClassLoader().getResourceAsStream("conf.properties")) ;
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			RECOVERY_MINUTE= Integer.parseInt(properties.getProperty("edit_authority_recovery_time"));
			properties.clear();
	}
	
	public void run() {
		try {
			Connection con = DBConnectionFactory.getConnection();
			PreparedStatement stmt = con
					.prepareStatement("delete from collaboration where expire_time<?");
			java.sql.Timestamp time = new java.sql.Timestamp(new Date().getTime());
			stmt.setTimestamp(1, time);
			int num = stmt.executeUpdate();
			stmt.close();
			con.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
